import axios from 'axios'
const baseURL = 'http://localhost:8090/'
//生成实例化对象
const fetch = axios.create({
    baseURL,
    timeout: 5000,
    headers: {}
});

//拦截器
// Add a request interceptor
fetch.interceptors.request.use(function (config) {
    //有一些需要token才能吊通接口
    config.headers.Authorization=localStorage.getItem('token')
    return config;
}, function (error) {
    return Promise.reject(error);
});

// Add a response interceptor
fetch.interceptors.response.use(function (response) {
    let res = null
    if (response.status == 200&&response.data.err==0) {
        res = response.data.data
    }
    return res
}, function (error) {
    return Promise.reject(error);
});
export default fetch